/**
 * 
 */
package ga.nqueens;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.jheuristics.Individual;
import org.jheuristics.ga.GAConfig;
import org.jheuristics.ga.operators.probabilities.ConstantProbability;

import junit.framework.TestCase;

/**
 * @author thiago
 *
 */
public class NQueensCycleXOverTest extends TestCase {

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * 
	 */
	public void testdoXOver(){
		
		NQueensCycleXOver xover = new NQueensCycleXOver(new ConstantProbability(1));
		
		List<Integer> g1 = new LinkedList<Integer>();
		for (int i = 0; i <= 8; i++) {
			g1.add(i);
		}
		
		List<Integer> g2 = new LinkedList<Integer>();
		g2.add(3);g2.add(0);g2.add(1);
		g2.add(7);g2.add(6);g2.add(5);
		g2.add(8);g2.add(2);g2.add(4);
		
		NQueensIndividualFactory queensIndividualFactory = new NQueensIndividualFactory(9);
		
		Individual p1 = queensIndividualFactory.createSpecificIndividual(g1, null);
		Individual p2 = queensIndividualFactory.createSpecificIndividual(g2, null);
		
		Individual[] ind = xover.dox(p1, p2, null, queensIndividualFactory);
		
		List<Integer> gexpected = new ArrayList<Integer>();
		gexpected.add(0);gexpected.add(1);gexpected.add(2);
		gexpected.add(3);gexpected.add(6);gexpected.add(5);
		gexpected.add(8);gexpected.add(7);gexpected.add(4);
		
		Individual expInd = queensIndividualFactory.createSpecificIndividual(gexpected, null);
		assertEquals(expInd.getGens(), ind[0].getGens());
	}
}
